<?php

defined('_JEXEC') or die();

jimport('joomla.application.component.controller');

class Easiv2adminControllerEditInstances extends JController {
	
	function cancel() {
		JRequest::setVar('view', 'manageInstances');
		
		parent::display();
	}
	
	function update() {
		$ids = JRequest::getVar('id');
		$db =& JFactory::getDBO();
		
		foreach($ids as $id) {
			$newName = JRequest::getVar($id.'_name');
			$newHttp = JRequest::getVar($id.'_http');
			$newFtp = JRequest::getVar($id.'_ftp');
			$newPort = JRequest::getVar($id.'_port');
			$newFolder = JRequest::getVar($id.'_folder');
			$newUser = JRequest::getVar($id.'_user');
			$newPass = JRequest::getVar($id.'_pass');
			
			if($newName == "")
				$newName = 'Default Site';
		
			if($newPort == "")
				$newPort = 21;
			
			if($newUser != "" && $newPass != "" && $newFtp != "" && $newHttp != "") {
				$db->setQuery("UPDATE #__easiv2_instances SET name = '".$newName."', http_address = '".$newHttp."', ftp_host = '".$newFtp."', port = '".$newPort."', ftp_user = '".$newUser."', ftp_pass = '".$newPass."' WHERE id = ".$id);
				
				if($db->query() != false) {
					echo "Update with ID <b>".$id."</b> was <span style=\"color:#0F0;\"><b>successful</b></span>!<br>";
				}
				else {
					echo "Update with ID <b>".$id." <span style=\"color:#0F0;\">failed!</b></span> Please try again.<br>";
				}
			}
			else {
				echo "Some information were missing. Please check again at ID <b>".$id."</b><br>";
			}
		}
		
		JRequest::setVar('view', 'manageInstances');
		parent::display();
	}
}